package com.team12.hotel404.service.serviceImpl;

import com.team12.hotel404.domain.User;
import com.team12.hotel404.domain.UserExample;
import com.team12.hotel404.mapper.UserMapper;
import com.team12.hotel404.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 列出所有的用户
     * @return
     */
    @Override
    public List<User> listAllUser() {
        return userMapper.selectByExample(new UserExample());
    }

    /**
     * 更新用户的信息
     * @param user
     */
    @Override
    public void updateUserInfo(User user) {
        userMapper.updateByPrimaryKeySelective(user);
    }

    /**
     * 插入用户信息
     * @param user
     */
    @Override
    public void insertUser(User user) {
        userMapper.insert(user);
    }

    /**
     * 通过用户名查找用户
     * @param userName
     * @return
     */
    @Override
    public User find(String  userName) {
        User user = userMapper.findByName(userName);
        return user;
    }

    /**
     * 通过id查找用户
     * @param id
     * @return
     */
    @Override
    public User findById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    /**
     * 通过手机号查找用户
     * @param userPhone
     * @return
     */
    @Override
    public User findByPhone(String userPhone) {
        return userMapper.selectByPhone(userPhone);
    }

    /**
     * 更新用户信息
     * @param user
     */
    @Override
    public void updateHotelInfo(User user) {
        userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int Regist(User user) {
        int u = userMapper.insert(user);
        return u;
    }

    @Override
    public int deleteUserById(Integer id) {

        return userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<User> listUserAll() {
        return null;
    }

    @Override
    public void updataStatus(User user1) {

        userMapper.updateByPrimaryKeySelective(user1);
    }
}
